package uk.ac.cam.juliet.zedcat.socialnetworking.plugin;


import javax.mail.Message.RecipientType;

import org.codemonkey.vesijama.Email;
import org.codemonkey.vesijama.Mailer;

import uk.ac.cam.juliet.zedcat.db.Account;
import uk.ac.cam.juliet.zedcat.socialnetworking.AbstractPlugin;

public class PingFMPlugin extends AbstractPlugin{

	public PingFMPlugin(Account acc) {
		super(acc.getAccountID(), acc.getUsername(), acc.getPassword());
	}

	public void pushUpdate(String update) {
		PingFMThread t = new PingFMThread(update);
		t.start();
	}

	public class PingFMThread extends Thread {
		String message;
		
		public PingFMThread(String message) {
			this.message = message;
		}
		
		public void run() {
			System.out.println("AccountID: " + accountid + " - Type: PingFM - Sending Email.");
			final Email email = new Email();
			email.setFromAddress("ZedCam", "zedcat@antibanter.com");
			email.setSubject(message);
			email.addRecipient("PingFM", "in9tj2@ping.fm", RecipientType.TO);
			email.setText("Update generated by Team Juliet");
			new Mailer("mail.antibanter.com", 26, "zedcat+antibanter.com", "AirFreshener").sendMail(email);
			System.out.println("AccountID: " + accountid + " - Type: Email - Ping Sent!");
		}
	}
}
